<!DOCTYPE html>
<html>

<head>
<#include "/common/head.html"/>
</head>

<body>
	<div class="layui-fluid">
		<div class="layui-row">
			<form method="post" class="layui-form layui-form-pane" lay-filter="form-val-filter">
				
	            <input type="hidden" id="id" name="id">
				
				<div class="layui-col-md6">
					<div class="layui-form-item">
						<label for="name" class="layui-form-label">账号</label>
						<div class="layui-input-block">
							<input type="text" placeholder="请输入账号" name="userName"
								lay-verify="required" autocomplete="off" class="layui-input" disabled="disabled"/>
						</div>
					</div>
	
					<div class="layui-form-item">
						<label for="name" class="layui-form-label">姓名</label>
						<div class="layui-input-block">
							<input type="text" name="name" placeholder="请输入姓名"
								lay-verify="required" autocomplete="off" class="layui-input"/>
						</div>
					</div>
				</div>
				<div class="layui-col-md6">
					<div class="layui-form-item">
						<label for="name" class="layui-form-label">状态</label>
						<div class="layui-input-block">
							<select name="disable" lay-verify="required">
								<option value="false">启用</option>
								<option value="true">禁用</option>
							</select>
						</div>
					</div>
				</div>
				<div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">
                        角色设置
                    </label>
                    
                    <div class="layui-input-block">
                    	<div id="roleset"></div>
                    </div>
                </div>

				<div class="layui-form-item">
				    <div class="layui-input-block">
				      <button type="submit" class="layui-btn" lay-submit lay-filter="add">提交</button>
				      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
				    </div>
				  </div>
				
			</form>
		</div>
	</div>
	<script>
	
		layui.use(function() {
			var form = layui.form;
			var transfer = layui.transfer;
			
			var id=getQueryString('id');
			apipost('/v1/user/page',{id:id},function(result){
				var data=result.data[0];
				data.disable=String(data.disable);
				form.val('form-val-filter',data);
				
				var haveRoleIds=[];
				for(var r in data.roles){
					haveRoleIds.push(data.roles[r].id);
				}
				apipost('/v1/role/page',{pageSize:999},function(result){
					transfer.render({
						id:'roleset',
						elem : '#roleset',
						data : result.data,
						title: ['所属角色', '授权角色'],
						parseData : function(res) {
							return {
								"value" : res.id,
								"title" : res.name,
								"disabled" : res.disabled,
								"checked" : res.checked
							};
						},
						value: haveRoleIds
					});
				});
			});

			form.on('submit(add)', function(data) {
				var roleIds = [];
				var roles=transfer.getData('roleset');
				for(var r in roles){
					roleIds.push(roles[r].value);
				}
				var field = data.field;
				field['roleIds'] = roleIds;
				winPut("/v1/user", convertFormParams(field));
				return false;
			});

		});
	</script>
</body>

</html>